<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>小球动画2</title>
	</head>
	<body>
	</body>
	<script src="jquery.js"></script>
	<script src="Ball.js"></script>
	<script>
		
		var balls = [];
		
		for (var i = 0;i<5;i++) {
			var ball = new Ball();
			balls.push(ball);
		}
		
		function moveBall(ball){
			ball.move();
			
			//判断是否和其他球碰撞
//			balls[0].isTouchWith(balls[1]);

			for (var i = 0;i<balls.length-1;i++) {
				for (var j = i+1;j<balls.length;j++) {
					balls[i].isTouchWith(balls[j]);
				}
			}
			
			requestAnimationFrame(moveBall.bind(this,ball));
			
			
		}
		
		for (var i = 0;i<balls.length;i++) {
			moveBall(balls[i]);
		}
		
		
	</script>
</html>
